package lxt.action;

import java.util.List;
import java.util.Map;
import lxt.action.core.ActionSupport;
import lxt.action.core.ParamTypes;
import lxt.entity.Parameter;
import lxt.service.ParameterService;

public class ParameterAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	/**
	 * 定义对象
	 */
	private List<Parameter> paramters;
	private String paramType;//参数类型
	private Parameter parameter;
	/**
	 * 定义接口
	 */
	private ParameterService parameterService;
	
	private String deleteIds;
	//定义分页变量
	private Integer pageCounts = 10; //每页显示数量
	private String currPageStr = "1"; //分页
	private Integer totalCounts ;//总数据量
	
	private List<Map<String, String>> parmTypes = ParamTypes.getParamTypes();
	
	public String loadAll(){
		try{
			//定义从第几条显示
			int offset =( Integer.parseInt(currPageStr)-1)*pageCounts;
			//获得list
			paramters = parameterService.loadParameter(paramType, offset, pageCounts);
			//获得总共数据量
			totalCounts = parameterService.loadAllParameterCount(paramType);
			
		}catch(Exception ex){
			ex.printStackTrace();
			this.addActionMessage("操作失败，请检查重新操作");
		}
		return SUCCESS;
	}

	public String addPre(){
		return SUCCESS;
	}
	
	public String add() {
		try {
			parameterService.addParameter(parameter);
		} catch (Exception e) {
			e.printStackTrace();
			this.addActionMessage(e.getMessage());
			return INPUT;
		}
		return SUCCESS;
	}
	
	public String updatePre(){
		try{
			parameter = parameterService.loadParameterById(parameter.getId());
		}catch(Exception e){
			e.printStackTrace();
			this.addActionMessage(e.getMessage());
		}
		return SUCCESS;
	}
	
	public String update(){
		try{
			parameterService.updateParameter(parameter);
		}catch(Exception e){
			e.printStackTrace();
			this.addActionMessage(e.getMessage());
			return INPUT;
		}
		return SUCCESS;
	}
	
	public String delete() {
		try {
			parameterService.deleteParameter(deleteIds);
		} catch (Exception e) {
			e.printStackTrace();
			this.addActionMessage(e.getMessage());
			return INPUT;
		}
		return SUCCESS;
	}
	
	
	public List<Parameter> getParamters() {
		return paramters;
	}

	public void setParamters(List<Parameter> paramters) {
		this.paramters = paramters;
	}

	public String getParamType() {
		return paramType;
	}

	public void setParamType(String paramType) {
		this.paramType = paramType;
	}

	public ParameterService getParameterService() {
		return parameterService;
	}

	public void setParameterService(ParameterService parameterService) {
		this.parameterService = parameterService;
	}

	public String getDeleteIds() {
		return deleteIds;
	}

	public void setDeleteIds(String deleteIds) {
		this.deleteIds = deleteIds;
	}

	public Integer getPageCounts() {
		return pageCounts;
	}

	public void setPageCounts(Integer pageCounts) {
		this.pageCounts = pageCounts;
	}

	public String getCurrPageStr() {
		return currPageStr;
	}

	public void setCurrPageStr(String currPageStr) {
		this.currPageStr = currPageStr;
	}

	public Integer getTotalCounts() {
		return totalCounts;
	}

	public void setTotalCounts(Integer totalCounts) {
		this.totalCounts = totalCounts;
	}

	public List<Map<String, String>> getParmTypes() {
		return parmTypes;
	}

	public Parameter getParameter() {
		return parameter;
	}

	public void setParameter(Parameter parameter) {
		this.parameter = parameter;
	}
}
